﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using System.Collections;
using System.Windows;
using System.Windows.Media;
using System.Windows.Media.Animation;
using Seta;
using CommomFunctions;
using System.Windows.Shapes;

namespace Listas
{
    public class Animations : CommomFunctions.Animations
    {
        /// <summary>
        /// cv -> a copy of the main "ctrls" variable
        /// tempLabel -> an auxiliary Label that will have the properties of the Label that we want
        /// to animate. It is the Label that will come and go from the memory to the list.
        /// labelDeslocado -> auxiliary Labels that will simulate the displacement of the labels that are in the
        /// list to accomodate the insertion of a node or its removal
        /// l1 -> an ArrayList which contains all the labels that will be animated
        /// memoryPos -> the memory position occupied by the node
        /// </summary>
        private ControlVariables cv = new ControlVariables();
        private Label tempLabel = new Label();
        private Label labelDeslocado;
        private ArrayList l1 = new ArrayList();
        private int memoryPos = 0;
        
        /// <summary>
        /// Creates a copy of the main "ctrls" variable and of the main Grid so that they are easier to access
        /// </summary>
        /// <param name="gd"></param>
        /// <param name="cVar"></param>
        public void createAnimations(Grid gd, ControlVariables cVar)
        {
            Gridi = gd;
            cv = cVar;
        }

        /// <summary>
        /// Animates the comes and goes of the Label from and to the memory
        /// </summary>
        /// <param name="pos"></param>
        /// <param name="posMemoLivre"></param>
        internal void animatePositioning(int pos, int posMemoLivre )
        {
            tempLabel = new Label();

            Gridi.Children.Add(tempLabel);
            Grid.SetRow(tempLabel, 0);
            Grid.SetRowSpan(tempLabel, 3);
            Grid.SetColumn(tempLabel, 0);
            Grid.SetColumnSpan(tempLabel, 9);
            tempLabel.Visibility = Visibility.Visible;
            tempLabel.Content = cv[pos].ToString();

            tempLabel.BorderBrush = Brushes.DeepPink;
            tempLabel.BorderThickness = new Thickness(2);
            tempLabel.Foreground = Brushes.Gold;
            tempLabel.FontSize = 30;
            tempLabel.FontWeight = FontWeights.Bold;
            tempLabel.Margin = new Thickness(cv.getMemory(posMemoLivre).Margin.Left, cv.getMemory(posMemoLivre).Margin.Top + 9, cv.getMemory(posMemoLivre).Margin.Right, cv.getMemory(posMemoLivre).Margin.Bottom);

            tempLabel.VerticalAlignment = VerticalAlignment.Bottom;
            tempLabel.HorizontalContentAlignment = HorizontalAlignment.Center;
            tempLabel.VerticalContentAlignment = VerticalAlignment.Center;
            tempLabel.Background = Brushes.Transparent;

            NameScope.SetNameScope(this.tempLabel, new NameScope());
            this.tempLabel.RegisterName("myAnimatedObject", tempLabel);

            ThicknessAnimationUsingKeyFrames myThicknessAnimation = new ThicknessAnimationUsingKeyFrames();

            double delay = 0;
            if ((posMemoLivre == 2) || (posMemoLivre == 5) || (posMemoLivre == 8) || (posMemoLivre == 11))
            {
                LinearThicknessKeyFrame contAdd2_contAdd1 = new LinearThicknessKeyFrame(new Thickness(cv.getMemory(posMemoLivre - 1).Margin.Left, cv.getMemory(posMemoLivre - 1).Margin.Top + 9, cv.getMemory(posMemoLivre - 1).Margin.Right, cv.getMemory(posMemoLivre - 1).Margin.Bottom));
                contAdd2_contAdd1.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0.3));
                myThicknessAnimation.KeyFrames.Add(contAdd2_contAdd1);

                LinearThicknessKeyFrame contAdd1_contAdd = new LinearThicknessKeyFrame(new Thickness(cv.getMemory(posMemoLivre - 2).Margin.Left, cv.getMemory(posMemoLivre - 2).Margin.Top + 9, cv.getMemory(posMemoLivre - 2).Margin.Right, cv.getMemory(posMemoLivre - 2).Margin.Bottom));
                contAdd1_contAdd.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0.6));
                myThicknessAnimation.KeyFrames.Add(contAdd1_contAdd);
                delay = 0.6;

            }
            else if ((posMemoLivre == 1) || (posMemoLivre == 4) || (posMemoLivre == 7) || (posMemoLivre == 10))
            {
                LinearThicknessKeyFrame contAdd1_contAdd = new LinearThicknessKeyFrame(new Thickness(cv.getMemory(posMemoLivre - 1).Margin.Left, cv.getMemory(posMemoLivre - 1).Margin.Top + 9, cv.getMemory(posMemoLivre - 1).Margin.Right, cv.getMemory(posMemoLivre - 1).Margin.Bottom));
                contAdd1_contAdd.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0.35));
                myThicknessAnimation.KeyFrames.Add(contAdd1_contAdd);
                delay = 0.35;

            }

            int ind;
            if (pos == 6)
            {
                ind = 5;
            }
            else ind = pos;


            LinearThicknessKeyFrame ml_centro = new LinearThicknessKeyFrame(new Thickness(cv.getLabel(ind).Margin.Left, 55, cv.getLabel(ind).Margin.Right, 230));
            delay += (7 - ind) * 0.35;
            ml_centro.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(delay));
            myThicknessAnimation.KeyFrames.Add(ml_centro);


            if (pos == 6)
            {

                LinearThicknessKeyFrame centro_baixo = new LinearThicknessKeyFrame(new Thickness(cv.getLabel(ind).Margin.Left, 55, cv.getLabel(ind).Margin.Right, 105));
                delay += 0.7;
                centro_baixo.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(delay));
                myThicknessAnimation.KeyFrames.Add(centro_baixo);

                LinearThicknessKeyFrame baixo_lado = new LinearThicknessKeyFrame(new Thickness(cv.getLabel(pos).Margin.Left, 55, cv.getLabel(pos).Margin.Right, 105));
                delay += 0.3;
                baixo_lado.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(delay));
                myThicknessAnimation.KeyFrames.Add(baixo_lado);

                LinearThicknessKeyFrame lado_posFinal = new LinearThicknessKeyFrame(new Thickness(cv.getLabel(pos).Margin.Left, cv.getLabel(pos).Margin.Top, cv.getLabel(pos).Margin.Right, cv.getLabel(pos).Margin.Bottom));
                delay += 0.3;
                lado_posFinal.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(delay));
                myThicknessAnimation.KeyFrames.Add(lado_posFinal);
            }
            else
            {
                LinearThicknessKeyFrame centro_baixo = new LinearThicknessKeyFrame(new Thickness(cv.getLabel(ind).Margin.Left, cv.getLabel(ind).Margin.Top, cv.getLabel(ind).Margin.Right, cv.getLabel(ind).Margin.Bottom));
                delay += 1;
                centro_baixo.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(delay));
                myThicknessAnimation.KeyFrames.Add(centro_baixo);
            }


            createStoryboard(myThicknessAnimation, Label.MarginProperty, delay + 0.5, animePosicionamento_Completed, this.tempLabel);
        }

        /// <summary>
        /// Executes when the animation simulating a node going back to memory to free it is completed
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        internal void animateRemovalPositioning_Completed(object sender, EventArgs e)
        {
            Gridi.Children.Remove(tempLabel);

            updateButtons();
            
            cv.getMemory(memoryPos).Background = Brushes.Transparent;

            if (cv.cont == 0)
            {
                cv.setNullImagesVisibility(Visibility.Visible);
                animateImageOpacity(cv.getImage(WorkingImage.BeginNull));
                animateImageOpacity(cv.getImage(WorkingImage.EndNull));
            }
        }

        /// <summary>
        /// 
        /// </summary>
        private void updateButtons()
        {
            cv.enableButtons();
            ButtonClicked[] bc = { ButtonClicked.Create };
            cv.updateButtons(bc, false);
        }

        /// <summary>
        /// Animates the node going back to memory to free it when it is a removal operation
        /// </summary>
        /// <param name="pos"></param>
        /// <param name="posMemoria"></param>
        internal void animatePositioningRemoval(int pos, int posMemoria)
        {
            this.memoryPos = posMemoria;
            tempLabel = new Label();

            Gridi.Children.Add(tempLabel);
            Grid.SetRow(tempLabel, 0);
            Grid.SetRowSpan(tempLabel, 3);
            Grid.SetColumnSpan(tempLabel, 9);
            tempLabel.Visibility = Visibility.Visible;
            tempLabel.Content = cv.getLabel(pos).Content.ToString();
            tempLabel.BorderBrush = Brushes.DeepPink;
            tempLabel.BorderThickness = new Thickness(2);
            tempLabel.Foreground = Brushes.Gold;
            tempLabel.FontSize = 30;
            tempLabel.FontWeight = FontWeights.Bold;
            tempLabel.Margin = new Thickness(cv.getLabel(pos).Margin.Left, cv.getLabel(pos).Margin.Top, cv.getLabel(pos).Margin.Right, cv.getLabel(pos).Margin.Bottom);

            tempLabel.VerticalAlignment = VerticalAlignment.Bottom;
            tempLabel.HorizontalContentAlignment = HorizontalAlignment.Center;
            tempLabel.VerticalContentAlignment = VerticalAlignment.Center;


            NameScope.SetNameScope(this.tempLabel, new NameScope());
            this.tempLabel.RegisterName("myAnimatedObject", tempLabel);

            ThicknessAnimationUsingKeyFrames myThicknessAnimation = new ThicknessAnimationUsingKeyFrames();

            int ind;
            if (pos == 6)
            {
                ind = 5;
            }
            else ind = pos;

            double delay = 1;

            if (pos == 6)
            {
                LinearThicknessKeyFrame sobe_lado = new LinearThicknessKeyFrame(new Thickness(cv.getLabel(pos).Margin.Left, 55, cv.getLabel(pos).Margin.Right, 105));
                sobe_lado.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0.4));
                myThicknessAnimation.KeyFrames.Add(sobe_lado);

                LinearThicknessKeyFrame lado_centro = new LinearThicknessKeyFrame(new Thickness(cv.getLabel(ind).Margin.Left, 55, cv.getLabel(ind).Margin.Right, 105));
                lado_centro.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0.9));
                myThicknessAnimation.KeyFrames.Add(lado_centro);

                delay += 1.0;
            }
            LinearThicknessKeyFrame centro_ml = new LinearThicknessKeyFrame(new Thickness(cv.getLabel(ind).Margin.Left, 55, cv.getLabel(ind).Margin.Right, 230));
            centro_ml.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(delay));
            myThicknessAnimation.KeyFrames.Add(centro_ml);

            delay += (7 - pos) * 0.35;

            if ((posMemoria == 1) || (posMemoria == 2))
            {
                LinearThicknessKeyFrame contAdd2_contAdd1 = new LinearThicknessKeyFrame(new Thickness(cv.getMemory(0).Margin.Left, cv.getMemory(0).Margin.Top + 9, cv.getMemory(0).Margin.Right, cv.getMemory(0).Margin.Bottom));
                contAdd2_contAdd1.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(delay));
                myThicknessAnimation.KeyFrames.Add(contAdd2_contAdd1);
            }

            if ((posMemoria == 4) || (posMemoria == 5))
            {
                LinearThicknessKeyFrame contAdd2_contAdd1 = new LinearThicknessKeyFrame(new Thickness(cv.getMemory(3).Margin.Left, cv.getMemory(3).Margin.Top + 9, cv.getMemory(3).Margin.Right, cv.getMemory(3).Margin.Bottom));
                contAdd2_contAdd1.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(delay));
                myThicknessAnimation.KeyFrames.Add(contAdd2_contAdd1);

            }

            if ((posMemoria == 7))
            {
                LinearThicknessKeyFrame contAdd2_contAdd1 = new LinearThicknessKeyFrame(new Thickness(cv.getMemory(6).Margin.Left, cv.getMemory(6).Margin.Top + 9, cv.getMemory(6).Margin.Right, cv.getMemory(6).Margin.Bottom));
                contAdd2_contAdd1.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(delay));
                myThicknessAnimation.KeyFrames.Add(contAdd2_contAdd1);
            }
            delay += 0.35;
            LinearThicknessKeyFrame contAdd1_contAdd = new LinearThicknessKeyFrame(new Thickness(cv.getMemory(posMemoria).Margin.Left, cv.getMemory(posMemoria).Margin.Top + 9, cv.getMemory(posMemoria).Margin.Right, cv.getMemory(posMemoria).Margin.Bottom));
            contAdd1_contAdd.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(delay));
            myThicknessAnimation.KeyFrames.Add(contAdd1_contAdd);

            if (cv.cont == 1)
            {
                myThicknessAnimation.BeginTime = TimeSpan.FromSeconds(0.3);
            }


            createStoryboard(myThicknessAnimation, Label.MarginProperty, delay + 1, animateRemovalPositioning_Completed, this.tempLabel);            
        }

        /// <summary>
        /// Executes when animation of the "comes" and "goes" from/to memory are completed
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void animePosicionamento_Completed(object sender, EventArgs e)
        {
            Gridi.Children.Remove(tempLabel);

            updateButtons();

            updateLabelsAfterAnimation(0);

            animaInsercaoArrow(cv.insertAtPosition);

            restoreImageOpacity(cv.getImage(WorkingImage.End));

            if (cv.getImage(WorkingImage.Begin).Opacity < 1)
                restoreImageOpacity(cv.getImage(WorkingImage.Begin));

            animateImageMargin(cv.getImage(WorkingImage.End), new Thickness(cv.getLabel(cv.cont - 1).Margin.Left + 10, 674 / 15.0, cv.getLabel(cv.cont - 1).Margin.Right + 10, 0),
                thImage_Completed);          

        }

        /// <summary>
        /// Changes the image opacity from 0 to 1
        /// </summary>
        /// <param name="image"></param>
        private void restoreImageOpacity(Image image)
        {
            DoubleAnimation dbImage = new DoubleAnimation(0, 1, new Duration(TimeSpan.FromSeconds((0.0))));
            image.BeginAnimation(Image.OpacityProperty, dbImage);            
        }

        /// <summary>
        /// Calls a function that adjusts the margins of all the images
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void thImage_Completed(object sender, EventArgs e)
        {
            cv.rebuild();
        }

        void animaDeslocamentoInsercao_Completed(object sender, EventArgs e)
        {
            foreach (Label lbl in l1)
            {
                Gridi.Children.Remove(lbl);
            }

            updateLabelsAfterAnimation(cv.insertAtPosition + 1);
            
        }

        void animaDeslocamentoRemocao_Completed(object sender, EventArgs e)
        {
            foreach (Label lbl in l1)
            {
                Gridi.Children.Remove(lbl);
            }

            updateLabelsAfterAnimation(0);
            
        }

        private void updateLabelsAfterAnimation(int ind)
        {
            for (int i = ind; i < cv.cont; i++)
            {
                cv.setLabelVisibility(i, Visibility.Visible);
                cv.seLabelContent(i, ((int)cv[i]).ToString());
            }
        }

        private void animateDisplacement(int contMoves, EventHandler animationCompleted, int contMovements)
        {
            labelDeslocado = new Label();

            Gridi.Children.Add(labelDeslocado);
            Grid.SetRow(labelDeslocado, 0);
            Grid.SetRowSpan(labelDeslocado, 3);
            Grid.SetColumnSpan(labelDeslocado, 9);
            labelDeslocado.Visibility = Visibility.Visible;
            labelDeslocado.FontSize = 30;
            labelDeslocado.Foreground = Brushes.LemonChiffon;
            labelDeslocado.BorderBrush = Brushes.DarkSeaGreen;
            labelDeslocado.BorderThickness = new Thickness(2);
            labelDeslocado.Content = cv.getLabel(contMoves).Content.ToString();
            labelDeslocado.Background = Brushes.ForestGreen;
            labelDeslocado.Margin = new Thickness(cv.getLabel(contMoves).Margin.Left, cv.getLabel(contMoves).Margin.Top, cv.getLabel(contMoves).Margin.Right, cv.getLabel(contMoves).Margin.Bottom);
            labelDeslocado.VerticalAlignment = VerticalAlignment.Bottom;
            labelDeslocado.VerticalContentAlignment = VerticalAlignment.Center;
            labelDeslocado.HorizontalContentAlignment = HorizontalAlignment.Center;
            l1.Add(labelDeslocado);

            NameScope.SetNameScope(this.labelDeslocado, new NameScope());
            this.labelDeslocado.RegisterName("myAnimatedObject", ((Label)l1[l1.Count - 1]));

            ThicknessAnimationUsingKeyFrames myThicknessAnimation = new ThicknessAnimationUsingKeyFrames();

            LinearThicknessKeyFrame A_C = new LinearThicknessKeyFrame(cv.getLabel(contMovements).Margin, KeyTime.Uniform);
            myThicknessAnimation.KeyFrames.Add(A_C);

            createStoryboard(myThicknessAnimation, Rectangle.MarginProperty, 2.5, animationCompleted, this.labelDeslocado);
        }

        internal void animaDeslocamentoInsercao(int contMoves)
        {
            animateDisplacement(contMoves, animaDeslocamentoInsercao_Completed, contMoves + 1);
        }

        internal void animaDeslocamentoRemocao(int contMoves)
        {
            animateDisplacement(contMoves, animaDeslocamentoRemocao_Completed, contMoves - 1);
            
        }
        #region Animações

        

        internal void animateArrow(int pos)
        {
            int inicio = pos;
            
            if (inicio < 0)
            {
                inicio = 0;
            }

            for (int i = inicio; i < cv.cont; i++)
            {
                DoubleAnimation dbX1 = new DoubleAnimation(cv.getArrowPosition(PositionType.X1, i), cv.getArrowPosition(PositionType.X1, i + 1), (Duration)TimeSpan.FromSeconds(1.0));
                DoubleAnimation dbX2 = new DoubleAnimation(cv.getArrowPosition(PositionType.X2, i), cv.getArrowPosition(PositionType.X2, i + 1), (Duration)TimeSpan.FromSeconds(1.0));
                animateArrowsPosition(i, dbX1, dbX2);    
            }
        }

        internal void animaInsercaoArrow(int pos)
        {
            DoubleAnimation db = new DoubleAnimation(0, 1, new Duration(new TimeSpan(0, 0, 2)));
            realocaSetasInsercao();

            if (pos > 0)
            {
                cv.getArrow(pos - 1).Visibility = Visibility.Visible;
                cv.getArrow(pos - 1).BeginAnimation(ArrowLine.OpacityProperty, db);
            }

            cv.getArrow(pos).Visibility = Visibility.Visible;
            cv.getArrow(pos).BeginAnimation(ArrowLine.OpacityProperty, db);
        }

        void realocaSetasInsercao()
        {
            cv.setAllArrowsHidden();

            for (int i = 0; i < cv.cont; i++)
            {
                DoubleAnimation dbX1A = new DoubleAnimation(cv.getArrow(i).X1, cv.getArrowPosition(PositionType.X1, i), (Duration)TimeSpan.FromSeconds(0.0));
                DoubleAnimation dbX2A = new DoubleAnimation(cv.getArrow(i).X2, cv.getArrowPosition(PositionType.X2, i), (Duration)TimeSpan.FromSeconds(0.0));

                animateArrowsPosition(i, dbX1A, dbX2A);
            }
        }

        internal void animaRemoveArrow(int pos)
        {
            for (int i = pos; i < cv.cont; i++)
            {
                DoubleAnimation dbX1 = new DoubleAnimation(cv.getArrowPosition(PositionType.X1, i), cv.getArrowPosition(PositionType.X1, i - 1), (Duration)TimeSpan.FromSeconds(1.0));
                DoubleAnimation dbX2 = new DoubleAnimation(cv.getArrowPosition(PositionType.X2, i), cv.getArrowPosition(PositionType.X2, i - 1), (Duration)TimeSpan.FromSeconds(1.0));
                dbX1.Completed += new EventHandler(dbX1_Completed);

                animateArrowsPosition(i, dbX1, dbX2);
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void dbX1_Completed(object sender, EventArgs e)
        {
            cv.setAllArrowsHidden();
            
            for (int i = 0; i < cv.cont; i++)
            {
                DoubleAnimation dbX1A = new DoubleAnimation(cv.getArrow(i).X1, cv.getArrowPosition(PositionType.X1, i), (Duration)TimeSpan.FromSeconds(0.0));
                DoubleAnimation dbX2A = new DoubleAnimation(cv.getArrow(i).X2, cv.getArrowPosition(PositionType.X2, i), (Duration)TimeSpan.FromSeconds(0.0));

                animateArrowsPosition(i, dbX1A, dbX2A);
            }
        }

        /// <summary>
        /// Changes the X values of an arrow to animate it
        /// </summary>
        /// <param name="ind"></param>
        /// <param name="dbX1"></param>
        /// <param name="dbX2"></param>
        private void animateArrowsPosition(int ind, DoubleAnimation dbX1, DoubleAnimation dbX2)
        {
            cv.getArrow(ind).Visibility = Visibility.Visible;
            cv.getArrow(ind).BeginAnimation(ArrowLine.X1Property, dbX1);
            cv.getArrow(ind).BeginAnimation(ArrowLine.X2Property, dbX2);
        }

        #endregion

        /// <summary>
        /// Animates the image's margin to repositionate the image
        /// </summary>
        /// <param name="img"></param>
        /// <param name="margemTempAux"></param>
        internal void animateImageMargin(Image img, Thickness margemTempAux)
        {
            ThicknessAnimation thAnimation = new ThicknessAnimation(img.Margin, margemTempAux, TimeSpan.FromSeconds(1.0));
            img.BeginAnimation(Image.MarginProperty, thAnimation);
        }

        internal void animateImageMargin(Image img, Thickness margemTempAux, double p)
        {
            ThicknessAnimation thAnimation = new ThicknessAnimation(img.Margin, margemTempAux, TimeSpan.FromSeconds(1.0));
            thAnimation.BeginTime = TimeSpan.FromSeconds(p);
            img.BeginAnimation(Image.MarginProperty, thAnimation);
        }
                
        internal void animateImageMargin(Image img, Thickness margemTempAux, EventHandler animationCompleted)
        {
            ThicknessAnimation thImage = new ThicknessAnimation(img.Margin, margemTempAux, new Duration(TimeSpan.FromSeconds((1.0))));
            thImage.Completed += new EventHandler(animationCompleted);
            img.BeginAnimation(Image.MarginProperty, thImage);
        }

        /// <summary>
        /// Animates image opacity from 0 to 1
        /// </summary>
        /// <param name="image"></param>
        internal void animateImageOpacity(Image image)
        {
            DoubleAnimation dbImage = new DoubleAnimation(0, 1, new Duration(TimeSpan.FromSeconds((0.5))));
            image.BeginAnimation(Image.OpacityProperty, dbImage);
        }

        /// <summary>
        /// Restores the original image opacity value
        /// </summary>
        /// <param name="image"></param>
        internal void unAnimateImageOpacity(Image image)
        {
            DoubleAnimation dbImage = new DoubleAnimation(1, 0, new Duration(TimeSpan.FromSeconds((0.5))));
            image.BeginAnimation(Image.OpacityProperty, dbImage);
        }

        /// <summary>
        /// Restores the original arrow opacity value
        /// </summary>
        /// <param name="myArrows"></param>
        /// <param name="pos"></param>
        internal void unAnimateArrowOpacity(Arrows myArrows, int pos)
        {
            DoubleAnimation db = new DoubleAnimation(1, 0, new Duration(TimeSpan.FromSeconds((0.5))));
            (myArrows.getArrow(pos)).BeginAnimation(ArrowLine.OpacityProperty, db);             
        }

    }
}
